#ifndef __PNNETSOCKET_H__
#define __PNNETSOCKET_H__

/**
*@file       pnnetsocket.h
*@brief      socket class
*
*@author     graywind
*@version    1.0.0.0
*@data       2011/11/16
*/

#include <string.h>
#include "boost/asio.hpp"
#include "pnhandlerfunctor.hpp"

///net service relative
namespace pnNetlib
{
	class PnNetSocket
	{
	private:
		///@brief     started yet
		bool                                  m_bIsStart;
		///@brief     socket object
		boost::asio::ip::tcp::socket          m_socket;

	public:
		///@brief     constructor
		PnNetSocket(boost::asio::io_service& ioService);
		///@brief     destructor
		~PnNetSocket();

	private:
		///@brief     callback function that after send msg
		void          send_handler();
		///@brief     callback function that after connect to the server
		void          connect_handler();
		///@brief     
		void          msg_handler();

	public:
		///@brief     started yet(read-only)
		const bool    is_start() const;

		///@brief     send msg
		///param[in]  pHeader  pointer of msg header
		///param[in]  pMsg     msg buffer head pointer
		///retval     void
		void          send(PnMsgHeader* pHeader, void* pMsg);

		///@brief     connect to acceptor
		///param[in]  ip         ip address connect to
		///param[in]  port       port connect to
		///retval     void
		void          connect(const std::string& ip, unsigned short port);

	public:
		///@brief     bind handler functor
		template<typename F>
		void attach_handler(F f);
	};
};